﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../Content/highlighter/styles/shCoreDefault.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>发布.net程序</h3>
    <b>advanceInstaller 13.1破解版下载</b><br />
    <p>
        最新的程序：
        <a href="http://nfinal.oss-cn-qingdao.aliyuncs.com/upload/advancedinstaller13-13.1.zip">点击下载</a><br />
        advinst.msi,安装只需一直下一步就可以了。
        安装完成后运行advanced.installer.v13.1.architect-patch.exe进行破解。
    </p>
    <b>生成自动安装基于TopSelf开发的跨平台服务</b>
    <p>
        新建Console应用程序项目MyService，并安装TopShelf安装包3.3.1。
        Install-Package Topshelf
        Install-Package Topshelf.Log4Net
    </p>
    <pre class="brush:csharp;">
        public class TownCrier
        {
            readonly Timer _timer;
            public TownCrier()
            {
                _timer = new Timer(1000) {AutoReset = true};
                _timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} and all is well", DateTime.Now);
            }
            public void Start() { _timer.Start(); }
            public void Stop() { _timer.Stop(); }
        }
        public class Program
        {
            public static void Main()
            {
                HostFactory.Run(x =>                                 //1
                {
                    x.Service<TownCrier>(s =>                        //2
                    {
                       s.ConstructUsing(name=> new TownCrier());     //3
                       s.WhenStarted(tc => tc.Start());              //4
                       s.WhenStopped(tc => tc.Stop());               //5
                    });
                    x.RunAsLocalSystem();                            //6

                    x.SetDescription("Sample Topshelf Host");        //7
                    x.SetDisplayName("Stuff");                       //8
                    x.SetServiceName("Stuff");                       //9
                });                                                  //10
            }
        }
    </pre>
    <b>设置自定义响应，完成服务自动安装过程</b>
    <p>
        点击Custom Behavior下的Custom Actions<br />
        <img src="../Content/images/knowledge/20171109113430.png" /><br/>
        Add Custom Action下点击Lauch file<br />
        <img src="../Content/images/knowledge/20171109113456.png" /><br />
        <b>1.设置安装服务：</b><br />
        Properties:<br />
        File to launch: 点击键盘上的'['会出现文件浏览框，选择编译生成的MyService.exe即可。<br />
        Command line: install<br />
        选中Hide program's window,隐藏窗口<br />
        选中Run as Administrator,使用管理员运行,xp以上版本需要选中<br />
        <br />
        Execution Stage Condition，运行条件<br />
        选中install
        xp下：(VersionNT < 600)<br />
        xp以上系统：(VersionNT >= 600)<br />
        把该命令拉至Install Execution Stage中的Add Resource下方。<br />
        <img src="../Content/images/knowledge/20171109115128.png" /><br />
        因为只能应用程序复制完成，才能运行。<br />
        <b>2.设置启动服务：</b><br />
        只有Command line为start<br />
        <b>3.设置服务停止：</b><br />
        Properties:<br />
        File to launch: 点击键盘上的'['会出现文件浏览框，选择编译生成的MyService.exe即可。<br />
        Command line: stop<br />
        选中Hide program's window,隐藏窗口<br />
        选中Run as Administrator,使用管理员运行,xp以上版本需要选中<br />

        Execution Stage Condition，运行条件<br />
        选中uninstall
        xp下：(VersionNT < 600)<br />
        xp以上系统：(VersionNT >= 600)<br />
        把该命令拉至Install Execution Stage中的Preparing下方。<br />
        <img src="../Content/images/knowledge/20171109115150.png" /><br />
        <b>4.设置服务卸载：</b><br />
        与停止相同。<br />
        只有Command line为uninstall<br />
    </p>
</body>
</html>